class Solution {
    public int removeElement(int[] nums, int val) {
        int oldnums = 0,newnums = 0;
        while(oldnums<nums.length) {
            if(val == nums[oldnums]) {
                oldnums++;
            }else {
                nums[newnums++] = nums[oldnums++];
            }
        }
        return newnums;
    }
}